/**
 * Created by Administrator on 2017/10/26
 */
import React from 'react';
import {Button, Col, message,Modal} from 'antd';
import {
    WeaSelect,
    WeaDialog,
    WeaTop,
    WeaBrowser,
    WeaScope,
    WeaRightMenu,
    WeaSearchGroup,
    WeaFormItem,
    WeaCheckbox,
    WeaTools,
    WeaError,
    WeaLocaleProvider,WeaDialogFooter,
    WeaHelpfulTip
} from 'ecCom';
import {WeaSwitch} from 'comsMobx';
import {inject, observer} from 'mobx-react';
import CofirmModal from './ConfirmModal';
import SaveAsTemplate from '../../public/wf-save-as-template';
import * as WORKFLOW_AGENT from '../../apis/agent';
import '../../style/agent.less';

const getLabel = WeaLocaleProvider.getLabel;

@inject('wfAgentStore')

@observer

export default class Main extends React.Component {
    constructor(props) {
        super(props);
        this.state = {

            repetitionValue: 1,
            date: '',
        }
    }
    componentDidMount() {
        const { wfAgentStore,location={} } = this.props;
        const queryParams = location.query || {};
        if(queryParams.isSingle == "true"){     //路由单页访问
            wfAgentStore.setUrlParams(queryParams);
            wfAgentStore.doAddAgentInit({symbol:"addAgent"}, false);
        }
    }
    handleCancel = () => {
        const {wfAgentStore} = this.props;
        wfAgentStore.addAgent(false);
    }

    saveAsTemplate(visible) {
        this.saveDataVertify().then((params)=>{
            if (!params) {
                return false;
            }else {
                this.template.click(visible);
            }
        })
    }

    saveDataVertify() {

        const {wfAgentStore} = this.props;
        const {addAgentForm,addAgentFlag} = wfAgentStore;
        const formParams = addAgentForm.getFormParams();
        let weaError = this.weaError;

        return new Promise(function(resolve) {
            addAgentForm.validateForm().then(f=>{
                if(f.isValid){
                    let endReturn = false;
                    // const formParams = addAgentForm.getFormParams();

                    // if (formParams.hasOwnProperty('templatename') && formParams.templatename === '') {
                    //     endReturn =  false;
                    //     resolve(endReturn);
                    //     return ;
                    // }
                    // else if (!formParams.hasOwnProperty('agentuid') || formParams.agentuid === '') {
                    //     endReturn =  false;
                    //     resolve(endReturn);
                    //     return ;
                    // }
                    // else if (!formParams.hasOwnProperty('bagentuid') || formParams.bagentuid === '') {
                    //     endReturn =  false;
                    //     resolve(endReturn);
                    //     return ;
                    // }

                    if (formParams.agentrange === '1' && (!formParams.hasOwnProperty('rangetype') || formParams.rangetype === '')) {
                        weaError.showError();
                        endReturn =  false;
                        resolve(endReturn);
                        return ;
                    } else if (formParams.isCreateAgenter === '0' && formParams.isProxyDeal === '0') {
                        const modal = Modal.warning({
                            title: getLabel(131329,'信息确认'),
                            content: getLabel(82678,'代理流程创建 和 代理流程处理 至少启用了一项'),
                            okText: getLabel(83446,'确定'),
                            onOk: () => modal.destroy()
                        });
                        endReturn =  false;
                        resolve(endReturn);
                        return ;
                    } else if (formParams.hasOwnProperty('userSelect')) {
                        if (formParams.userSelect !== 'all' && formParams.agentuid === formParams.userSelect.split('_')[1]) {
                            Modal.warning({
                                title: getLabel(131329,'信息确认'),
                                content: getLabel(129504,'被代理人、代理人不能相同！'),
                                okText: getLabel(83446,'确定')
                            });
                            endReturn =  false;
                            resolve(endReturn);
                            return ;
                        }
                    } else if (formParams.agentuid === formParams.bagentuid) {
                        Modal.warning({
                            title: getLabel(131329,'信息确认'),
                            content: getLabel(129504,'被代理人、代理人不能相同！'),
                            okText: getLabel(83446,'确定')
                        });
                        endReturn =  false;
                        resolve(endReturn);
                        return ;
                    }

                    if ((addAgentFlag === 'addAgent' || addAgentFlag === 'importTemplate') && !wfAgentStore.verifyTime('addAgentForm')) {
                        endReturn =  false;
                        resolve(endReturn);
                        return ;
                    }

                    endReturn = formParams;

                    resolve(endReturn);
                }else{
                    f.showErrors();
                    if (formParams.agentrange === '1' && (!formParams.hasOwnProperty('rangetype') || formParams.rangetype === '')) {
                        let endReturn = false;
                        weaError.showError();
                        endReturn =  false;
                        resolve(endReturn);
                        return ;
                    }
                    // this.setState({date: new Date()}); // 改变一个state的变量,强制页面刷新
                }

            });
        })
    }

    handleSave = () =>  {
        this.saveDataVertify().then((params)=>{
            if (!params) {
                return;
            }
            const {wfAgentStore} = this.props;
            const { verifyAgentOverlap, addAgentFlag, addAgentDatas } = wfAgentStore;
            if (!addAgentDatas.hasOwnProperty("userSelect")) {
                delete params.userSelect;
            }
            if (addAgentFlag === 'importTemplate') {
                this.verifyAgentOverlap({method: "add", ...params});
            }else {
                verifyAgentOverlap({method: "add", ...params});
            }
        });
    }

    verifyAgentOverlap(params = {}) {
        const {wfAgentStore} = this.props;
        WORKFLOW_AGENT.verifyAgentOverlap(params).then(datas => {
            // wfAgentStore.repetitionValue = 0;
            if (datas.overlapCount > 0) {  //弹出重复处理选项(1、新代理去重复；2、新代理覆盖已重复)
                wfAgentStore.overlapIds = datas.overlapIds;
                wfAgentStore.repetitionValue = datas.overlapCount;
            } else {
                this.dataSave(params);
            }

        });
    }

    dataSave(params = {}) {
        const {wfAgentStore,location={}} = this.props;
        const {addAgentVisible} = wfAgentStore;
        if (addAgentVisible) {
            wfAgentStore.isDisabled = true;
            message.loading(getLabel(383498,'正在添加，请稍候...'), 0);
            WORKFLOW_AGENT.addAgentSave(params).then(datas => {
                const {agentresult} = datas;
                if (agentresult === 'success') {
                    wfAgentStore.addAgent(false);
                    this.props.closeImportModal();
                    message.destroy();
                    message.success(getLabel(83880,'添加成功'));
                    wfAgentStore.reload();
                    // wfAgentStore.doSearch();
                } else {
                    message.destroy();
                    message.error(getLabel(31877,'添加失败'));
                }
            });
        }
    }

    handleSaveTemplate = () => {
        this.saveDataVertify().then((params)=>{
            if (!params) {
                return;
            }
            const {wfAgentStore} = this.props;
            const {addAgentFlag, agentid} = wfAgentStore;

            wfAgentStore.isDisabled = true;
            if (addAgentFlag === 'addTemplate') {
                message.loading(getLabel(383498,'正在添加，请稍候...'), 0);
            } else if (addAgentFlag === 'editTemplate') {
                message.loading(getLabel(383500,'正在修改，请稍候...'), 0);
            }

            if (addAgentFlag === 'editTemplate') {
                params = {'templateid': agentid, ...params};
            }

            WORKFLOW_AGENT.saveAgentTemplate(params).then((datas) => {
                if (datas.api_status) {
                    if (addAgentFlag === 'addTemplate') {
                        message.destroy();
                        message.success(getLabel(83880,'添加成功'));
                    } else if (addAgentFlag === 'editTemplate') {
                        message.destroy();
                        message.success(getLabel(383312,'修改成功'))
                    }
                    wfAgentStore.addAgent(false);
                    wfAgentStore.isDisabled = false;
                    this.props.reloadManagerModal();
                } else {
                    if (addAgentFlag === 'addTemplate') {
                        message.destroy();
                        message.error(getLabel(31877,'添加失败'));
                        wfAgentStore.isDisabled = false;
                    } else if (addAgentFlag === 'editTemplate') {
                        message.destroy();
                        message.error(getLabel(31436,'修改失败'))
                        wfAgentStore.isDisabled = false;
                    }
                }
            }, () => {
                if (addAgentFlag === 'addTemplate') {
                    message.destroy();
                    message.error(getLabel(31877,'添加失败'));
                    wfAgentStore.isDisabled = false;
                } else if (addAgentFlag === 'editTemplate') {
                    message.destroy();
                    message.error(getLabel(31436,'修改失败'))
                    wfAgentStore.isDisabled = false;
                }
            })
        })
    }

    saveTemplateOk = (v) => {
        this.saveDataVertify().then((params)=>{
            if (!params) {
                return;
            }
            const {wfAgentStore} = this.props;
            params = {...params, templatename: v};
            wfAgentStore.saveAgentTemplate(params);
        })
    }

    confirmOk = (v) =>  {
        const {wfAgentStore} = this.props;
        const {addAgentForm, dataSave, addAgentFlag} = wfAgentStore;

        let params = addAgentForm.getFormParams();
        params = {...params, ...{method: "add"}};
        params["overlapMethod"] = v;

        if (addAgentFlag === 'importTemplate') {
            this.dataSave(params);
        } else {
            dataSave(params);
        }
        this.confirmCancel();
    }

    confirmCancel = () => {
        const {wfAgentStore} = this.props;
        wfAgentStore.repetitionValue = 0;
    }

    bagentuidChange = (obj) =>  {
        const {wfAgentStore} = this.props;
        const userid = WeaTools.ls.getJSONObj('theme-account').userid;
        if (userid === obj.bagentuid.value) {
            wfAgentStore.bagentuidChange(true);
        } else {
            wfAgentStore.bagentuidChange(false);
        }
    }

    startDateChange = (obj) => {
        const {wfAgentStore} = this.props;
        wfAgentStore.startDateChange(obj, 'addAgentDatas')

    }

    endDateChange = (obj) =>  {

        const {wfAgentStore} = this.props;
        wfAgentStore.endDateChange(obj, 'addAgentDatas')
    }

    startTimeChange = (obj) =>  {
        const {wfAgentStore} = this.props;
        wfAgentStore.startTimeChange(obj, 'addAgentForm');
    }

    endTimeChange = (obj) => {
        const {wfAgentStore} = this.props;
        wfAgentStore.endTimeChange(obj, 'addAgentForm');

    }

    getFooter() {
        const {wfAgentStore} = this.props;
        const {addAgentFlag,isDisabled} = wfAgentStore;
        let btns = [];
        if (addAgentFlag === 'addAgent' || addAgentFlag === 'importTemplate') {
            btns.push(
                <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@whwe2e@save`} disabled={isDisabled} type='primary' onClick={this.handleSave}>{getLabel(86,'保存')}</Button>
            )
        } else {
            btns.push(
                <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@59mrsf@save`} disabled={isDisabled} type='primary' onClick={this.handleSaveTemplate}>{getLabel(86,'保存')}</Button>
            )
        }

        if (addAgentFlag === 'addAgent') {

            btns.push(
                <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@fa0qth@saveAsTemplate`} disabled={isDisabled} type='primary' onClick={() => this.saveAsTemplate(true)}>{getLabel(18418,'存为模板')}</Button>
            )
        }

        // btns.push(
        //     <Button disabled={isDisabled} type="glost" onClick={() => this.handleCancel()}>取消</Button>
        // )

        return btns;
    }

    onChangeTemplateName(data,length = 200) {

        const {wfAgentStore} = this.props;
        const value = data.templatename.value;
        const { addAgentForm } = wfAgentStore;

        const charLength = value.replace(/[\u0391-\uFFE5]/g,"aaa").length;

        if(charLength > length) {

            let endStr = '';

            for(let i = length; i > 0; i--) {

                endStr = value.substring(0,i);

                const charLength = endStr.replace(/[\u0391-\uFFE5]/g,"aaa").length;

                if(charLength <= length) {
                    break ;
                }
            }

            let timer = setTimeout(()=>{
                addAgentForm.updateFields({
                    templatename :  endStr
                },false);
            },0)

            return ;
        }

        // addAgentForm.validateForm().then(f=>{
        //     if(f.isValid){
        //         // 验证通过, balabala业务代码
        //     }else{
        //         f.showErrors();
        //         this.setState({date: new Date()}); // 改变一个state的变量,强制页面刷新
        //     }
        // });
    }

    getSearchs() {

        const {wfAgentStore} = this.props;
        const {addAgentForm, addAgentDatas, addAgentFlag} = wfAgentStore;

        const {isFormInit} = addAgentForm;

        if (!isFormInit) {
            return;
        }

        const formParams = addAgentForm.getFormParams();
        const formDatas = addAgentForm.getFormDatas();

        let group = [];
        let items = [];

        if (addAgentDatas.hasOwnProperty('templatename')) {
            items.push(
                {
                    com: (
                        <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@ji286d@templatename`}
                            label={addAgentDatas.templatename.label}
                            labelCol={{span: 6}}
                            wrapperCol={{span: 18}}
                            error={addAgentForm.getError(addAgentDatas.templatename)}
                            tipPosition="bottom"
                            className="wf-agent-shortbrowser"
                        >
                            <div className="wf-templatename">
                                <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@9fozwf@templatename`}
                                    fieldConfig={addAgentDatas.templatename}
                                    form={addAgentForm}
                                    formParams={formParams}
                                    onChange={(data)=>this.onChangeTemplateName(data,200)}
                                />
                            </div>
                        </WeaFormItem>),
                    colSpan: 1
                }
            )
        }

        items.push(
            {
                com: (
                    <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@dl2wo9@bagentuid`}
                        label={addAgentDatas.bagentuid.label}
                        labelCol={{span: 6}}
                        wrapperCol={{span: 18}}
                        error={addAgentForm.getError(addAgentDatas.bagentuid)}
                        tipPosition="bottom"
                        className="wf-agent-shortbrowser"
                    >
                        <div className="wf-bagentuid">
                            <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@mkgc37@bagentuid`}
                                fieldConfig={addAgentDatas.bagentuid}
                                form={addAgentForm}
                                formParams={formParams}
                                onChange={this.bagentuidChange}

                            />
                        </div>
                        {
                            addAgentDatas.hasOwnProperty('userSelect') &&
                            <div className="wf-bagent-userSelect">
                                <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@wl6xgk@$userSelect`}
                                    fieldConfig={addAgentDatas.userSelect}
                                    form={addAgentForm}
                                    formParams={formParams}
                                />
                            </div>
                        }
                    </WeaFormItem>),
                colSpan: 1
            }, {
                com: (
                    <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@o6jdf7@shortbrowser`}
                        label={addAgentDatas.agentuid.label}
                        labelCol={{span: 6}}
                        wrapperCol={{span: 18}}
                        error={addAgentForm.getError(addAgentDatas.agentuid)}
                        tipPosition="bottom"
                        className="wf-agent-shortbrowser"
                    >
                        <div className="wf-agentuid">
                            <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@dw0mny@agentuid`}
                                fieldConfig={addAgentDatas.agentuid}
                                form={addAgentForm}
                                formParams={formParams}
                            />
                        </div>
                    </WeaFormItem>),
                colSpan: 1
            },
        );
        if (addAgentFlag === 'addAgent' || addAgentFlag === 'importTemplate') {
            items.push(
                {
                    com: (
                        <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@9kwhp0@addAgentFlag`}
                            label={`${getLabel(740,'开始日期')},${getLabel(131410,'时间')}`}
                            labelCol={{span: 6}}
                            wrapperCol={{span: 18}}
                        >
                            <div className="wf-agent-date">
                                <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@26zpj1@addAgentFlag`}
                                    fieldConfig={addAgentDatas.beginDate}
                                    form={addAgentForm}
                                    formParams={formParams}
                                    onChange={this.startDateChange}
                                />
                            </div>
                            <div className="wf-agent-time">
                                <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@wzcaaj@addAgentFlag`}
                                    fieldConfig={addAgentDatas.beginTime}
                                    form={addAgentForm}
                                    formParams={formParams}
                                    onChange={this.startTimeChange}
                                />
                            </div>
                        </WeaFormItem>),
                    colSpan: 1
                }, {
                    com: (
                        <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@znbqup@addAgentFlag`}
                            label={`${getLabel(741,'结束日期')},${getLabel(131410,'时间')}`}
                            labelCol={{span: 6}}
                            wrapperCol={{span: 18}}
                        >
                            <div className="wf-agent-date">
                                <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@4yssxu@addAgentFlag`}
                                    fieldConfig={addAgentDatas.endDate}
                                    form={addAgentForm}
                                    formParams={formParams}
                                    onChange={this.endDateChange}
                                />
                            </div>
                            <div className="wf-agent-time">
                                <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@to0g7g@addAgentFlag`}
                                    fieldConfig={addAgentDatas.endTime}
                                    form={addAgentForm}
                                    formParams={formParams}
                                    onChange={this.endTimeChange}
                                />
                            </div>
                        </WeaFormItem>),
                    colSpan: 1
                }
            )
        }
        const isCreateAgenterTxt = getLabel(515615,'代理创建子流程');
        items.push(
            {
                com: (
                    <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@spz0ez@isCreateAgenter`}
                        label={getLabel(383538,'代理流程创建')}
                        labelCol={{span: 6}}
                        wrapperCol={{span: 18}}
                    >
                        <div>
                            <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@s5uiqc@isCreateAgenter`} span={11}>
                                <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@07ea7p@isCreateAgenter`}
                                    fieldConfig={addAgentDatas.isCreateAgenter}
                                    form={addAgentForm}
                                    formParams={formParams}
                                />
                            </Col>
                            {
                                formDatas.hasOwnProperty('isCreateAgenter') && formDatas.isCreateAgenter.value === '1' &&
                                <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@0be2ag@isCreateAgenter`} span={11}>
                                    <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@jmaxwz@isCreateAgenter`} title={`${getLabel(515615,'代理创建子流程')}:`} className='wf-agent-isProxyDeal' span={16} style={{overflow:'hidden',textOverflow:'ellipsis',whiteSpace:'nowrap',lineHeight:'30px'}}>{isCreateAgenterTxt}:</Col>
                                    <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@q5g3h9@isCreateAgenter`}
                                        fieldConfig={addAgentDatas.isSysCreateAgenter}
                                        form={addAgentForm}
                                        formParams={formParams}
                                    />
                                    <span style={{position: 'absolute', top: 4}} >
                                        <WeaHelpfulTip ecId={`${this && this.props && this.props.ecId || ''}_WeaHelpfulTip@w90a0w@isCreateAgenter`}
                                            style={{paddingLeft: '20px'}}
                                            class="icon-coms-Explain isCreateAgenter-Explain"
                                            width={230}
                                            title={getLabel(515521, "启用后，设置了代理关系的流程在作为子流程被触发时，将以代理人的身份创建子流程")}
                                        />
                                    </span>
                                </Col>
                            }

                        </div>
                    </WeaFormItem>),
                colSpan: 1
            }, {
                com: (
                    <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@ybzhj9@isProxyDeal`}
                        label={getLabel(82585,'代理流程处理')}
                        labelCol={{span: 6}}
                        wrapperCol={{span: 18}}
                    >
                        <div>
                            <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@mn98ko@isProxyDeal`} span={11}>
                                <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@rxluni@isProxyDeal`}
                                    fieldConfig={addAgentDatas.isProxyDeal}
                                    form={addAgentForm}
                                    formParams={formParams}
                                />
                            </Col>
                            {
                                formDatas.hasOwnProperty('isProxyDeal') && formDatas.isProxyDeal.value === '1' &&
                                <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@qlqltz@isProxyDeal`} span={11}>
                                    <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@donzs0@isProxyDeal`} title={`${getLabel(33250,'代理已有待办事宜')}:`} className='wf-agent-isProxyDeal' span={16} style={{overflow:'hidden',textOverflow:'ellipsis',whiteSpace:'nowrap',lineHeight:'30px'}}>{getLabel(33250,'代理已有待办事宜')}:</Col>
                                    <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@p9tejt@isProxyDeal`}
                                        fieldConfig={addAgentDatas.isPendThing}
                                        form={addAgentForm}
                                        formParams={formParams}
                                    />
                                </Col>
                            }

                        </div>
                    </WeaFormItem>),
                colSpan: 1
            }, {
                com: (
                    <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@nfw3sw@rangetype`}
                        label={getLabel(383507,'代理流程范围')}
                        labelCol={{span: 6}}
                        wrapperCol={{span: 18}}
                        error={addAgentForm.getError(addAgentDatas.rangetype)}
                        tipPosition="bottom"
                    >
                        <div className="wf-agent-rangeleft">
                            <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@a2yd84@rangetype`}
                                fieldConfig={addAgentDatas.agentrange}
                                form={addAgentForm}
                                formParams={formParams}
                            />
                        </div>
                        {
                            formDatas.hasOwnProperty('agentrange') && formDatas.agentrange.value === '1' &&
                            <div className="wf-agent-rangeright">
                                <WeaError ecId={`${this && this.props && this.props.ecId || ''}_WeaError@ia0ua2@rangetype`}
                                    ref={weaErroe => this.weaError = weaErroe}
                                    tipPosition="bottom"
                                    error={formDatas.rangetype.value === '' ? `"${getLabel(383507,'代理流程范围')}"${getLabel(21423,'未填写')}` : ''}
                                >
                                    <div className="rangetype">
                                        <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@2qt9a7@rangetype`}
                                            fieldConfig={addAgentDatas.rangetype}
                                            form={addAgentForm}
                                            formParams={formParams}
                                        />
                                    </div>
                                </WeaError>
                            </div>
                        }
                    </WeaFormItem>),
                colSpan: 1
            }
        );
        group.push(<WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@1hzomc@addgroup`} col={1} needTigger={false} className="wf-agent-addgroup" title={getLabel(1361,'基本信息')} showGroup={true}
                                   items={items}/>)
        return group;
    }

    getMoreBtns () {

        const {wfAgentStore} = this.props;
        const {addAgentFlag,isDisabled} = wfAgentStore;

        const title = this.getTitle();

        let btns = {
            datas: [],
            collectParams: {
                favname: title,
                favouritetype: 2,
                objid: 0,
                importantlevel: 1,
            }
        };

        if (addAgentFlag === 'addAgent' || addAgentFlag === 'importTemplate') {
            btns.datas.push(
                {
                    key: '0',
                    disabled: isDisabled,
                    icon:  <i className='icon-coms-Preservation'/>,
                    content: getLabel(86,'保存'),
                    onClick:  this.handleSave,
                }
            )
        } else {
            btns.datas.push(
                {
                    key: '1',
                    disabled: isDisabled,
                    icon: <i className='icon-coms-Preservation'/>,
                    content: getLabel(86,'保存'),
                    onClick: this.handleSaveTemplate,
                }
            )
        }

        if (addAgentFlag === 'addAgent') {
            btns.datas.push(
                {
                    key: '2',
                    disabled: isDisabled,
                    icon: <i className="icon-coms-Reopen"/> ,
                    content: getLabel(18418,'存为模板'),
                    onClick: key => this.saveAsTemplate(true),
                }
            )
        }

        return btns;
    }

    //获取title
    getTitle () {

        const {wfAgentStore} = this.props;
        const {addAgentFlag} = wfAgentStore;

        let title = '';

        if (addAgentFlag === 'addAgent') {
            title = getLabel(33242,'新建代理');
        } else if (addAgentFlag === 'addTemplate') {
            title = getLabel(28051,'新建模板');
        } else if (addAgentFlag === 'editTemplate') {
            title = getLabel(28052,'编辑模板');
        } else if (addAgentFlag === 'importTemplate') {
            title = getLabel(383511,'从模板中导入并新建代理');
        }

        return title;
    }

    render() {
        const {wfAgentStore,location={}} = this.props;
        const {addAgentVisible, repetitionValue, overlapIds, addAgentFlag, addAgentForm,loading} = wfAgentStore;

        const {isFormInit} = addAgentForm;

        const title = this.getTitle();
        const isSingle = location.query && location.query.isSingle =="true";
        const Content = (
            <div style={{height:'100%',overflow:'auto'}}>
                <WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@rt1m44`}
                    {...this.getMoreBtns()}
                >
                    {isFormInit && this.getSearchs()}

                </WeaRightMenu>

                <SaveAsTemplate ecId={`${this && this.props && this.props.ecId || ''}_SaveAsTemplate@jht8m9`}
                    ref={template => this.template = template}
                    // btnName="存为模板"
                    modolName= {getLabel(18418,'存为模板')}
                    length={200}
                    // disabled={isDisabled}
                    btnStyle={{marginRight:'10px'}}
                    // lengthWarning={length => message.warning(`模板名称长度不能超过${length}个字符`)}
                    click={() => this.saveAsTemplate(true)}
                    handleOk={this.saveTemplateOk}
                />
                <CofirmModal ecId={`${this && this.props && this.props.ecId || ''}_CofirmModal@qo59o4`}
                    visible={repetitionValue !== 0}
                    handleOk={this.confirmOk}
                    handleCancel={this.confirmCancel}
                    repetitionValue={repetitionValue}
                    overlapIds={overlapIds}
                    method={"add"}
                />
            </div>
        );
        if(isSingle){
            return (
                <WeaTop ecId={`${this && this.props && this.props.ecId || ''}_WeaTop@zcgwcj`}
                    title={title}
                    loading={loading}
                    icon={<i className="icon-coms-workflow" />}
                    iconBgcolor="#0079DE"
                    buttons={this.getFooter()}
                    buttonSpace={10}
                    showDropIcon={true}
                    dropMenuDatas={this.getMoreBtns().datas}
                >
                    <div className="wf-agent-modal wf-agent-add">
                        {Content}
                    </div>
                </WeaTop>
            )
        }else{
            return (
                <div>
                    <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@o6vqb2`}
                        className={'wf-agent-modal wf-agent-add '}
                        visible={addAgentVisible}
                        title={title}
                        icon="icon-coms-workflow"
                        iconBgcolor='#0079DE'
                        maskClosable={false}
                        buttons={this.getFooter()}
                        onCancel={this.handleCancel}
                        style={{
                            width: "700px",
                            height: (addAgentFlag === 'editTemplate' || addAgentFlag === 'addTemplate') ? 440 : 495
                        }}
                        moreBtn={this.getMoreBtns()}
                        hasScroll
                    >
                        {Content}
                    </WeaDialog>
                </div>
            )
        }
    }

}


